package com.meitianhui.convenitenbuy.config;

import android.content.Context;
import android.text.TextUtils;

import com.meitianhui.convenitenbuy.Constants;
import com.meitianhui.convenitenbuy.main.model.bean.HyphenateInfo;
import com.meitianhui.convenitenbuy.main.model.bean.UserToken;
import com.meitianhui.convenitenbuy.module.mine.model.ConsumerAddress;
import com.meitianhui.convenitenbuy.module.mine.model.ConsumerInfo;
import com.meitianhui.convenitenbuy.module.mine.model.UserAsset;
import com.meitianhui.convenitenbuy.module.mine.model.UserInfo;
import com.meitianhui.convenitenbuy.util.PreferenceUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/10/31.
 * 获取存储信息数据
 */

public class InfoProvider {

    /**
     * 获取app_token
     */
    public static String getAppToken(Context context){
        return PreferenceUtils.getString(context, Constants.APP_TOKEN_KEY,"");
    }
    /**
     * 获取app security_code
     */
    public static String getAppSecurityCode(Context context){
        return PreferenceUtils.getString(context,Constants.APP_SECURITY_CODE,"");
    }
    /**
     * 是否是登录状态
     */
    public static boolean getLoginStatus(Context context){
        int login = PreferenceUtils.getInt(context,Constants.LOGIN_STATUS,0);
        boolean loginStatus = false;
        if(login==1){
            loginStatus = true;
        }
        return loginStatus;
    }
    /**
     * 获取user_token 对象
     */
    public static UserToken getUserToken(Context context){
        return (UserToken) PreferenceUtils.readObject(context,Constants.USER_TOKEN);
    }
    /**
     * 获取用户信息
     */
    public static UserInfo getUserInfo(Context context){
        return (UserInfo) PreferenceUtils.readObject(context,Constants.USER_INFO);
    }
    /**
     * 获取消费者信息
     */
    public static ConsumerInfo getConsumerInfo(Context context){
        return (ConsumerInfo) PreferenceUtils.readObject(context,Constants.CONSUMER_INFO);
    }

    /**
     * 获取用户信息
     */
    public static HyphenateInfo getHyphenateInfo(Context context){
        return (HyphenateInfo) PreferenceUtils.readObject(context,Constants.HYPHENATE_INFO);
    }


    /**
     * 获取用户资产
     */
    public static UserAsset getUserAsset(Context context){
        return (UserAsset) PreferenceUtils.readObject(context,Constants.USER_ASSET);
    }

    /**
     * 获取存储的城市位置名称
     */
    public static String getCity(Context context){
        String city = PreferenceUtils.getString(context,Constants.CITY,"");
        return TextUtils.isEmpty(city) ? "定位中" : city;
    }

    /**
     * 获取经度
     * @param context
     * @return
     */
    public static String getLongitude(Context context){
        return PreferenceUtils.getString(context,Constants.LONGITUDE,"");
    }
    /**
     * 获取纬度
     * @param context
     * @return
     */
    public static String getLatitude(Context context){
        return PreferenceUtils.getString(context,Constants.LATITUDE,"");

    }

    /**
     * 获取区域code
     */

    public static String getAreaCode(Context context){
        return PreferenceUtils.getString(context, Constants.AREA_CODE ,"");
    }


    /**
     * 获取默认门店ID
     */

    public static String getDefaultStoreId(Context context){
        return PreferenceUtils.getString(context,Constants.DEFAULT_STORE_ID,"");

    }
    /**
     * 获取默认门店名称
     */

    public static String getDefaultStoreName(Context context){
        return PreferenceUtils.getString(context,Constants.DEFAULT_STORE_NAME,"");
    }

    /**
     * 获取本地缓存地址
     */

    public static List<ConsumerAddress.ConsumerData> getUserReceivingAddress(Context context){
        return (List<ConsumerAddress.ConsumerData>)PreferenceUtils.readObject(context,Constants.USER_RECEIVING_ADDRESS);
    }

}
